package com.llseven.ai.spring.llseven.controller;

import com.llseven.ai.spring.llseven.business.BtnGraphBusiness;
import com.llseven.ai.spring.llseven.dto.input.GenerateImageInput;
import com.llseven.ai.spring.llseven.dto.output.BtnImageGenerateOutput;
import com.llseven.ai.spring.llseven.dto.output.BtnImageTaskInfoOutput;
import com.llseven.ai.spring.llseven.business.impl.BtnGraphBusinessImpl;
import com.llseven.ai.spring.llseven.dto.input.GenerateTaskInput;
import com.llseven.ai.spring.llseven.model.ResultModel;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;

/**
 * @author ywb
 * @date 2025-04-16 13:46
 */
@RestController
@Tag(name = "纽扣图片生成-模块", description = "示例控制器的描述")
@RequestMapping("/btn/image")
public class BtnGraphController {
    final BtnGraphBusiness business;
    
    public BtnGraphController(BtnGraphBusinessImpl business) {
        this.business = business;
    }
    
    
    @Operation(summary = "上传图片并生成")
    @PostMapping(value = "/generate", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public ResultModel<BtnImageGenerateOutput> generate(
//        @RequestPart("input") @Valid GenerateImageInput input,
        @RequestPart(value = "refImg", required = false) MultipartFile refImg,
        @RequestParam(value = "prompt") String prompt,
        @RequestParam(value = "strength", defaultValue = "0.35") Double strength,
        @RequestParam(value = "modelType", defaultValue = "stable-diffusion-3.5-large") String modelType
    ) {
        GenerateImageInput input = new GenerateImageInput();
        input.setPrompt(prompt);
        input.setStrength(strength);
        input.setModelType(modelType);
        return ResultModel.success(business.generate(input, refImg));
    }
    
    @Operation(summary = "获取")
    @GetMapping("/tasks")
    public ResultModel<BtnImageTaskInfoOutput> tasks(
        @ParameterObject @Valid GenerateTaskInput input
    ) {
        return ResultModel.success(business.getTask(input));
    }
}
